package com.firexxx.study.server.asyncservlet.controller;

import com.firexxx.study.server.asyncservlet.service.TestService;
import com.firexxx.study.performancetest.timeconsume.ConsumeTaskType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description: TODO
 * @throws:
 * @author: zhuangzhang2
 * @date: 2020/04/06 15:57
 */
@RestController("/")
public class TestController {

    @Autowired
    private TestService testService;

    @GetMapping("sync")
    public String sync(@RequestParam String delay, @RequestParam String taskType) throws InterruptedException {
        return testService.sync(Long.valueOf(delay), ConsumeTaskType.valueOf(taskType));
    }

    @GetMapping("async")
    public ListenableFuture<String> async(@RequestParam String delay, @RequestParam String taskType) throws InterruptedException {
        return testService.async(Long.valueOf(delay), ConsumeTaskType.valueOf(taskType));
    }

}